<?php
namespace app\manager\controller;

class CarCountry extends BaseController
{
    protected $check_auths = false; 
    /**
     * GET shwo carcountry info list
     * @return [type] [description]
     */
    public function index()
    {
        $list = model('CarCountries')->getCarCountriesLists();
        $this->assign('list',$list);
        return view('p/carcountry/index');

    }
    /**
     * GET show carcountry info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function read($id)
    {
        
    }

    /**
     * GET shwo create carcountry info
     * @return [type] [description]
     */
    public function create()
    {
        
        return view('p/carcountry/create');
    }
    /**
     * POST create new carcountry info
     * @return [type] [description]
     */
    public function save()
    {
        
        $post_carcountry_info['name'] = input('post.name');
        $post_carcountry_info['profiles'] = input('post.profiles');

        $carcountry = model('CarCountries')->createCarCountry($post_carcountry_info);
        
        if($carcountry){
            return $this->success(lang('create carcountry success'), '/carcountry');
        }
            return $this->error(lang('create carcountry failed').$carcountry['msg']);
        
    }

    /**
     * GET edit carcountry info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function edit($id)
    {
        $data = model('CarCountries')->getcarcountryInfo($id);
        $this->assign('data',$data);
        $this->assign('id',$id);
        return view('p/carcountry/edit');
    }

    /**
     * PUT update carcountry info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function update($id)
    {
        $post_carcountry_info['name'] = input('post.name');
        $post_carcountry_info['profiles'] = input('post.profiles');
        
        $carcountry = model('CarCountries')->updateCarCountry($id, $post_carcountry_info);

        if($carcountry){
            return $this->success(lang('update carcountry success'), '/carcountry');
        }
            return $this->error(lang('update carcountry failed').$carcountry['msg']);

    }
    
    /**
     * DELETE carcountry info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    /**
     * DELETE carcate info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function delete($id)
    {
       $ids=input('post.ids/a');
        if (empty($ids)) {
          return $this->error('请选择要删除的选项'); 
        }
        $count = model('CarCountries')->delInfo($ids);
        if ($count) {
           return $this->success('删除成功','/carcountry');
        }
        return $this->error('删除失败');
    }
}

